package com.lc.user.express.httpserver;

import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.core.PoiItem;
import com.lc.user.express.model.UsedRouteModel;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/8.附近车辆
 */
@HttpInlet(Net.GET_NEARBY_CARS)
public class GetNearByCars extends ZJDBAsyGet<GetNearByCars.Info> {
    public String userid,point;

    public GetNearByCars(String userid,String point,AsyCallBack listener) {
        super(listener);
        this.userid = userid;
        this.point = point;
    }

    @Override
    protected Info parser(JSONObject object) {
        if (object.optInt("message") == 1) {
            Info info = new Info();
            JSONArray array = object.optJSONArray("list");
            if(array != null){
                for (int i = 0; i<array.length(); i++){
                    JSONObject jsonObject = array.optJSONObject(i);
                    String[] s = jsonObject.optString("point").split(",");
                    LatLonPoint latLonPoint = new LatLonPoint(Double.valueOf(s[0]), Double.valueOf(s[1]));
                    PoiItem p = new PoiItem("", latLonPoint, "", "");
                    info.dataList.add(p);
                }

            }
            return info;
        }
        return null;
    }

    public static class Info {
        public List<PoiItem> dataList = new ArrayList<>();

    }
}
